class Solution {
    public void moveZeroes(int[] nums) {
        int dest =-1;
        int cur = 0;
        for(;cur< nums.length;cur++){
            if(nums[cur]==0){
                cur ++;

            }else{
                swap(nums,dest+1,cur);
                dest++;
                cur++;
            }
        }
    }
    public void swap(int[] nums,int i,int j){
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
    public void duplicateZeros(int[] arr) {
        int cur =0;
        int dest =-1;
        //找到最后一个要复写的数
        while(dest<arr.length-1){
            if(arr[cur]!=0){
                dest++;

            }else{
                // if(dest+1 == arr.length){
                //     arr[dest+1] = 0;
                //     cur--;
                //     break;

                // }
                dest+=2;


            }
            if(dest!= arr.length-1){
                cur++;
            }

        }
        System.out.println(arr[cur]);
        System.out.println(dest);
        while(cur >=0){
            if(arr[cur]!=0){
                arr[dest]=arr[cur];
                dest--;
                cur--;
            }else{
                arr[dest]=0;

                arr[dest-1]=0;
                dest-=2;
                cur--;
            }

        }

    }


    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.duplicateZeros(new int[]{1,0,2,3,0,4,5,0});
    }
}